import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: 路由配置项
 *
 * hidden: true                     // 当设置 true 的时候该路由不会再侧边栏出现 如401，login等页面，或者如一些编辑页面/edit/1
 * alwaysShow: true                 // 当你一个路由下面的 children 声明的路由大于1个时，自动会变成嵌套的模式--如组件页面
 *                                  // 只有一个时，会将那个子路由当做根路由显示在侧边栏--如引导页面
 *                                  // 若你想不管路由下面的 children 声明的个数都显示你的根路由
 *                                  // 你可以设置 alwaysShow: true，这样它就会忽略之前定义的规则，一直显示根路由
 * redirect: noRedirect             // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
 * name:'router-name'               // 设定路由的名字，一定要填写不然使用<keep-alive>时会出现各种问题
 * query: '{"id": 1, "name": "ry"}' // 访问路由的默认传递参数
 * roles: ['admin', 'common']       // 访问路由的角色权限
 * permissions: ['a:a:a', 'b:b:b']  // 访问路由的菜单权限
 * meta : {
    noCache: true                   // 如果设置为true，则不会被 <keep-alive> 缓存(默认 false)
    title: 'title'                  // 设置该路由在侧边栏和面包屑中展示的名字
    icon: 'svg-name'                // 设置该路由的图标，对应路径src/assets/icons/svg
    breadcrumb: false               // 如果设置为false，则不会在breadcrumb面包屑中显示
    activeMenu: '/system/user'      // 当路由设置了该属性，则会高亮相对应的侧边栏。
  }
 */

// 公共路由
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect')
      }
    ]
  },
  {
    path: '/loginxs',
    component: () => import('@/views/loginx'),
    hidden: true
  },
  {
    path: '/login',
    component: () => import('@/views/login'),
    hidden: true
  },
  
  {
    path: '/register',
    component: () => import('@/views/register'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error/401'),
    hidden: true
  },
  {
    path: '',
    component: Layout,
    redirect: 'index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/analysiswarning/Analysisview'),
        name: 'Index',
        meta: { title: '首页', icon: 'dashboard', affix: true }
      },
    ]
  },
  // {
  //   path: '/user',
  //   component: Layout,
  //   hidden: true,
  //   redirect: 'noredirect',
  //   children: [
  //     {
  //       path: 'profile',
  //       component: () => import('@/views/system/user/profile/index'),
  //       name: 'Profile',
  //       meta: { title: '个人中心', icon: 'user' }
  //     }
  //   ]
  // },
  // 1
  {
    path: '/analysiswarning',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'analysisview',
        component: () => import('@/views/analysiswarning/Analysisview'),
        name: 'Analysisview',
        meta: { title: '深度分析预警信息总览', affix: false }
      },
      {
        path: 'expmanage',
        component: () => import('@/views/analysiswarning/Expmanage'),
        name: 'Expmanage',
        meta: { title: '运维经验深度分析体系管理', affix: false }
      },
      {
        path: 'healthmanage',
        component: () => import('@/views/analysiswarning/Healthmanage'),
        name: 'Healthmanage',
        meta: { title: '健康评分体系管理', affix: false }
      },
      {
        path: 'logmanage',
        component: () => import('@/views/analysiswarning/Logmanage'),
        name: 'Logmanage',
        meta: { title: '日志深度分析体系管理', affix: false }
      },
      {
        path: 'dailywarning',
        component: () => import('@/views/analysiswarning/Dailywarning'),
        name: 'Dailywarning',
        meta: { title: '日检任务深度分析预警', affix: false }
      },
      // {
      //   path: 'dailywarningscri',
      //   component: () => import('@/views/analysiswarning/Dailywarningscript'),
      //   name: 'Dailywarningscript',
      //   meta: { title: '日检任务深度分析预警', affix: false }
      // },
      {
        path: 'baselinewarning',
        component: () => import('@/views/analysiswarning/Baselinewarning'),
        name: 'Baselinewarning',
        meta: { title: '基线深度分析预警', affix: false }
      },
      // {
      //   path: 'baselinewarningscri',
      //   component: () => import('@/views/analysiswarning/Baselinewarningscript'),
      //   name: 'Baselinewarningscri',
      //   meta: { title: '基线深度分析预警', affix: false }
      // },
      {
        path: 'expscript',
        component: () => import('@/views/analysiswarning/Expscript'),
        name: 'Expscript',
        meta: { title: '运维经验深度分析脚本应用', affix: false }
      },
      {
        path: 'healthscript',
        component: () => import('@/views/analysiswarning/Healthscript'),
        name: 'Healthscript',
        meta: { title: '健康评分脚本应用', affix: false }
      },
      {
        path: 'logscript',
        component: () => import('@/views/analysiswarning/Logscript'),
        name: 'Logscript',
        meta: { title: '日志深度分析脚本应用', affix: false }
      },
    ]
  },
  // 2
  {
    path: '/diagmanage',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'intelligentdiagnosis',
        component: () => import('@/views/diagmanage/intelligentdiagnosis'),
        name: 'intelligentdiagnosis',
        meta: { title: '智能诊断', affix: false }
      },
      {
        path: 'inspectionreport',
        component: () => import('@/views/diagmanage/inspectionreport'),
        name: 'inspectionreport',
        meta: { title: '状态巡检报告', affix: false },
      },

      {
        path: 'databasereport',
        component: () => import('@/views/diagmanage/databasereport'),
        name: 'databasereport',
        meta: { title: '数据库深度分析报告', affix: false },
      },
      {
        path: 'querydia',
        component: () => import('@/views/diagmanage/Querydia'),
        name: 'querydia',
        meta: { title: '巡检报告查询', affix: false },
      },
      // {
      //   path: 'diagmanagescript',
      //   component: () => import('@/views/diagmanage/diagmanagescript'),
      //   name: 'diagmanagescript',
      //   meta: { title: '巡检报告查询', affix: false },
      // },
      {
        path: 'indiaecharts',
        component: () => import('@/views/diagmanage/diaecharts/indiaecharts'),
        name: 'indiaecharts',
        meta: { title: '状态巡检报告查看', affix: false },
      },



    ]
  },
  // 3
  {
    path: '/expertmodel',
    component: Layout,
    hidden: true,
    children: [

      {
        path: 'healthmodel',
        component: () => import('@/views/expertmodel/HealthModel'),
        name: 'healthmodel',
        meta: { title: '健康模型管理', affix: false },
      },
      {
        path: 'LoadModel',
        component: () => import('@/views/expertmodel/LoadModel'),
        name: 'LoadModel',
        meta: { title: '负载模型管理', affix: false },
      },
      {
        path: 'performance',
        component: () => import('@/views/expertmodel/PerformanceModel'),
        name: 'performance',
        meta: { title: '性能模型管理', affix: false },
      },



    ]
  },
  // 4
  {
    path: '/knowledgebase',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'knowledge',
        component: () => import('@/views/knowledgebase/Knowledge'),
        name: 'knowledge',
        meta: { title: '知识库管理', affix: false },
      },

    ]
  },
  // {
  //   path: '/system',
  //   component: Layout,
  //   hidden: true,
  //   children: [
  //     {
  //       path: 'user',
  //       component: () => import('@/views/system/user'),
  //       name: 'user',
  //       meta: { title: '用户管理', affix: false },
  //     },

  //   ]
  // },
  // 5
  {
    path: '/formwork',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'baseformwork',
        component: () => import('@/views/formwork/Baseformwork'),
        name: 'baseformwork',
        meta: { title: '基线模板体系管理', affix: false },
      },
      {
        path: 'operationformwork',
        component: () => import('@/views/formwork/Operationformwork'),
        name: 'operationformwork',
        meta: { title: '运维经验模板体系管理', affix: false },
      },
      {
        path: 'warnformwork',
        component: () => import('@/views/formwork/Warnformwork'),
        name: 'warnformwork',
        meta: { title: '基线告警模板体系管理', affix: false },
      },
    ]
  },
  // 6
  {
    path: '/devops',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'comcheck/harddep',
        component: () => import('@/views/devops/Harddep'),
        name: 'Harddep',
        meta: { title: '建转运硬件设备管理', affix: false }
      },
      {
        path: 'comcheck/hardscript',
        component: () => import('@/views/devops/Hardscript'),
        name: 'Hardscript',
        meta: { title: '建转运硬件设备检查脚本应用', affix: false }
      },
      {
        path: 'comcheck/softdep',
        component: () => import('@/views/devops/Softdep'),
        name: 'Softdep',
        meta: { title: '建转运软件系统管理', affix: false }
      },
      {
        path: 'comcheck/softscript',
        component: () => import('@/views/devops/Softscript'),
        name: 'Softscript',
        meta: { title: '建转运软件系统检查脚本应用', affix: false }
      },
      {
        path: 'comcheck/hisreport',
        component: () => import('@/views/devops/Hisreport'),
        name: 'Hisreport',
        meta: { title: '历史检查报告', affix: false }
      },
      {
        path: 'comcheck/checktemp',
        component: () => import('@/views/devops/Checktemp'),
        name: 'Checktemp',
        meta: { title: '合规检查模板', affix: false }
      },
      {
        path: 'comcheck/checkmodel',
        component: () => import('@/views/devops/Checkmodel'),
        name: 'Checkmodel',
        meta: { title: '合规检查模块', affix: false }
      },
      {
        path: 'comcheck/checkdep',
        component: () => import('@/views/devops/Checkdep'),
        name: 'checkdep',
        meta: { title: '检查项管理', affix: false }
      },

      {
        path: 'comcheck/scriptadd',
        component: () => import('@/views/devops/Scriptadd'),
        name: 'scriptadd',
        meta: { title: '指标采集脚本', affix: false }
      },

      {
        path: 'loopholecheck',
        component: () => import('@/views/devops/Loopholecheck'),
        name: 'Loopholecheck',
        meta: { title: '漏洞检查', affix: false }
      },
      {
        path: 'loopholereport',
        component: () => import('@/views/devops/Loopholereport'),
        name: 'Loopholereport',
        meta: { title: '漏洞报告', affix: false }
      },
      {
        path: 'comcheck/intemmanage',
        component: () => import('@/views/devops/intemmanage'),
        name: 'Hisreport',
        meta: { title: '巡检模板管理', affix: false }
      },
      {
        path: 'comcheck/inttaskmanage',
        component: () => import('@/views/devops/inttaskmanage'),
        name: 'Hisreport',
        meta: { title: '巡检任务管理', affix: false }
      },
      {
        path: 'comcheck/inrepmanage',
        component: () => import('@/views/devops/inrepmanage'),
        name: 'Hisreport',
        meta: { title: '巡检报告管理', affix: false }
      },
      {
        path: 'comcheck/douactive',
        component: () => import('@/views/devops/douactive'),
        name: 'Hisreport',
        meta: { title: '双活工具', affix: false }
      },
      {
        path: 'screen/comprehensive',
        component: () => import('@/views/devops/Comprehensive'),
        name: 'Comprehensive',
        meta: { title: '综合大屏', affix: false }
      },
      {
        path: 'screen/example',
        component: () => import('@/views/devops/Example'),
        name: 'Example',
        meta: { title: '实例大屏', affix: false }
      },
    ]
  },
  // 7
  {
    path: '/process',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'knowscript',
        component: () => import('@/views/process/knowscript'),
        name: 'knowscript',
        meta: { title: '知识点脚本审核', affix: false }
      },
      {
        path: 'indexscript',
        component: () => import('@/views/process/Indexscript'),
        name: 'Indexscript',
        meta: { title: '指标采集脚本审核', affix: false }
      },
      {
        path: 'comscript',
        component: () => import('@/views/process/Comscript'),
        name: 'Comscript',
        meta: { title: '合规检查项审核', affix: false }
      },
    ]
  },
  {
    path: '/log',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'operlog',
        component: () => import('@/views/monitor/operlog'),
        name: 'operlog',
        meta: { title: '操作日志', affix: false }
      },
      {
        path: 'logininfor',
        component: () => import('@/views/monitor/logininfor'),
        name: 'logininfor',
        meta: { title: '操作登录', affix: false }
      },

    ]
  },
]

// 动态路由，基于用户权限动态去加载
export const dynamicRoutes = [
  {
    path: '/system/user-auth',
    component: Layout,
    hidden: true,
    permissions: ['system:user:edit'],
    children: [
      {
        path: 'role/:userId(\\d+)',
        component: () => import('@/views/system/user/authRole'),
        name: 'AuthRole',
        meta: { title: '分配角色', activeMenu: '/system/user' }
      }
    ]
  },
  {
    path: '/system/role-auth',
    component: Layout,
    hidden: true,
    permissions: ['system:role:edit'],
    children: [
      {
        path: 'user/:roleId(\\d+)',
        component: () => import('@/views/system/role/authUser'),
        name: 'AuthUser',
        meta: { title: '分配用户', activeMenu: '/system/role' }
      }
    ]
  },
  {
    path: '/system/dict-data',
    component: Layout,
    hidden: true,
    permissions: ['system:dict:list'],
    children: [
      {
        path: 'index/:dictId(\\d+)',
        component: () => import('@/views/system/dict/data'),
        name: 'Data',
        meta: { title: '字典数据', activeMenu: '/system/dict' }
      }
    ]
  },
  {
    path: '/monitor/job-log',
    component: Layout,
    hidden: true,
    permissions: ['monitor:job:list'],
    children: [
      {
        path: 'index/:jobId(\\d+)',
        component: () => import('@/views/monitor/job/log'),
        name: 'JobLog',
        meta: { title: '调度日志', activeMenu: '/monitor/job' }
      }
    ]
  },
  {
    path: '/tool/gen-edit',
    component: Layout,
    hidden: true,
    permissions: ['tool:gen:edit'],
    children: [
      {
        path: 'index/:tableId(\\d+)',
        component: () => import('@/views/tool/gen/editTable'),
        name: 'GenEdit',
        meta: { title: '修改生成配置', activeMenu: '/tool/gen' }
      }
    ]
  }
]

// 防止连续点击多次路由报错
let routerPush = Router.prototype.push;
let routerReplace = Router.prototype.replace;
// push
Router.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(err => err)
}
// replace
Router.prototype.replace = function push(location) {
  return routerReplace.call(this, location).catch(err => err)
}

export default new Router({
  //mode: 'history', // 去掉url中的#
  mode: 'hash', // 去掉url中的#
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})
